package com.aw.baselib.widgets.font

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Canvas
import android.graphics.Rect
import android.util.AttributeSet
import android.view.View
import com.aw.baselib.R
import com.aw.baselib.base.AwBaseApplication

/**
 * @author : hzw
 * https://blog.csdn.net/yuanxw44/article/details/80019501
 */
@SuppressLint("AppCompatCustomView")
class AwEtRegularHasParent(context: Context?, attrs: AttributeSet?) : AwEtRegularBase(
    context!!, attrs
) {
    init {
        typeface = AwBaseApplication.instance?.typefaceRegular
    }

    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
    }

    override fun setViewBg() {
        val view = parent as View
        if (view != null) {
            view.background = resources.getDrawable(R.drawable.bg_common_input_empty)
        }
    }

    override fun onFocusChanged(focused: Boolean, direction: Int, previouslyFocusedRect: Rect?) {
        super.onFocusChanged(focused, direction, previouslyFocusedRect)
        val layout = parent as View
        if (focused) {
            layout.background = resources.getDrawable(R.drawable.bg_common_input_active)
        } else {
            layout.background = resources.getDrawable(R.drawable.bg_common_input_normal)
        }
    }
}